package com.june.springmvc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.june.springmvc.pojo.User;
import com.june.springmvc.service.UserService;
import com.june.springmvc.mapper.UserMapper;

@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userDao;

	@Override
	public User save(User user) {
		userDao.insertSelective(user);
		return user;
	}

	@Override
	public List<User> save(List<User> users) {
		for (User user : users) {
			userDao.insertSelective(user);
		}
		return users;
	}

	@Override
	public void delete(User user) {
		userDao.deleteByPrimaryKey(user.getId());
	}
	
	@Override
	public void batchDelete(String[] ids){
		for(String id : ids){
			userDao.deleteByPrimaryKey(Integer.valueOf(id));
		}
	}

	@Override
	public User findOne(User user) {
		return userDao.selectByPrimaryKey(user.getId());
	}
	
	@Override
	public List<User> findPageData(User pojo,Integer pageNumber,Integer pageSize) {
		return userDao.selectPageBySelective(pojo, (pageNumber-1)*pageSize, pageSize);
	}

	@Override
	public Integer selectCount(User user) {
		return userDao.selectCount(user);
	}

}
